{{!
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
}}

<div class="col-md-12">
  {{app-timeout-bar app=model.app}}
</div>

{{#if actionResponse}}
  <div class="col-md-12">
    <div class="alert alert-dismissible {{if (eq actionResponse.type 'error') 'alert-danger' 'alert-success'}}" role="alert">
      <button class="close" data-dismiss="alert" aria-label="Close" {{action "resetActionResponse"}}><span aria-hidden="true">&times;</span></button>
      <strong>{{actionResponse.msg}}</strong>
    </div>
  </div>
{{/if}}

{{#if isLoading}}
  <div class="panel panel-default service-action-mask">
    <img src="assets/images/spinner.gif" alt="Loading...">
  </div>
{{/if}}

{{#if model.app.diagnostics}}
  <div class="col-md-12 margin-bottom-20">
    {{#if model.app.isFailed}}
      <div class="panel panel-danger">
        <div class="panel-heading">
          Diagnostics
        </div>
        <div class="panel-body" style="white-space: pre-wrap;">{{model.app.diagnostics}}</div>
      </div>
    {{else}}
      <div class="panel panel-default">
        <div class="panel-heading">
          Diagnostics
        </div>
        <div class="panel-body">{{model.app.diagnostics}}</div>
      </div>
    {{/if}}
  </div>
{{/if}}

{{#unless model.serviceName}}
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading">
        Outstanding Resource Requests
        {{#if totalOutstandingResourceRequests}}
          <span class="pull-right">
            Total: &lt;Memory: {{totalOutstandingResourceRequests.memory}},
              vCores: {{totalOutstandingResourceRequests.vCores}}&gt;
          </span>
        {{/if}}
      </div>
      <table class="display table table-striped table-bordered"
            cellspacing="0" width="100%">
        <thead>
        <tr>
          <th>Priority</th>
          <th>Resource Name</th>
          <th>Capability</th>
          <th># Containers</th>
          <th>Relax Locality</th>
          <th>Node Label Expression</th>
        </tr>
        </thead>
        <tbody>
        {{#each model.app.resourceRequests as |request|}}
          <tr>
            <td>{{request.priority}}</td>
            <td>{{request.resourceName}}</td>
            <td>&lt;Memory: {{request.capability.resourceInformations.resourceInformation.[0].value}},
              vCores: {{request.capability.resourceInformations.resourceInformation.[1].value}}&gt;</td>
            <td>{{request.numContainers}}</td>
            <td>{{request.relaxLocality}}</td>
            <td>
              {{#if request.nodeLabelExpression}}
                {{request.nodeLabelExpression}}
              {{else}}
                N/A
              {{/if}}
            </td>
          </tr>
        {{else}}
          <tr>
            <td class="text-center" colspan="6">No data available!</td>
          </tr>
        {{/each}}
        </tbody>
      </table>
    </div>
  </div>
{{/unless}}

<div class="col-md-12">
  <div class="panel panel-default">
    <div class="panel-heading">Scheduling Info</div>
    <table class="display table table-striped table-bordered"
            cellspacing="0" width="100%">
      <thead>
      <tr>
        <th>Allocated Resource</th>
        <th>Running Containers</th>
        <th>Preempted Resource</th>
        <th>Num Non-AM container preempted</th>
        <th>Num AM container preempted</th>
        <th>Aggregated Resource Usage</th>
      </tr>
      </thead>

      <tbody>
      <tr>
        <td>{{model.app.allocatedResource}}</td>
        <td>{{model.app.runningContainersNumber}}</td>
        <td>{{model.app.preemptedResource}}</td>
        <td>{{model.app.numNonAMContainerPreempted}}</td>
        <td>{{model.app.numAMContainerPreempted}}</td>
        <td>{{model.app.aggregatedResourceUsage}}</td>
      </tr>
      </tbody>
    </table>
  </div>
</div>

{{confirm-dialog
  dialogId="stopServiceConfirmDialog"
  message=(concat 'Are you sure you want to stop service "' model.serviceName '" for user "' model.app.user '" ?')
  action="stopService"
}}

{{confirm-dialog
  dialogId="deleteServiceConfirmDialog"
  message=(concat 'Are you sure you want to delete service "' model.serviceName '" for user "' model.app.user '" ?')
  action="deleteService"
}}
